package cc.dd.marketing.rule;

import cc.dd.marketing.core.domain.RuleInnerDTO;
import cc.dd.marketing.rule.base.Rule;
import cc.dd.marketing.rule.base.RuleChecker;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 规则校验
 *
 * @author dongsufeng
 * @date 2022/9/9 2:33 PM
 */
@Component
public class RuleEngine extends CheckerEngine<Rule, RuleChecker> {
    /**
     * 规则引擎执行方法
     *
     * @param request
     * @param rules
     * @return
     */
    public Boolean validate(final RuleInnerDTO request, List<Rule> rules) {
        return (new CheckerProcess<Rule>() {
            public Boolean _process(Rule rule) {
                return RuleEngine.this.getChecker(rule).validate(rule, request);
            }
        }).process(rules);
    }
}
